﻿using Microsoft.AspNetCore.Mvc;
using Nasty.Core.LoadParams;
using Nasty.Core.Registry;
using Nasty.FlowModule.Areas.FlowConfig.Model;
using Nasty.FlowModule.Areas.FlowConfig.Params;
using NetTaste;

namespace Nasty.FlowModule.FlowConfig
{
	public interface IFlowConfigService : IAutofacRegister
	{
		public Nasty.Core.Entity.Flow.FlowConfig GetFlowConfig(string id);

		public List<Nasty.Core.Entity.Flow.FlowConfig> GetFlowConfigs(GetFlowConfigsParams @params);

        public ResultData<Nasty.Core.Entity.Flow.FlowConfig> SaveFlowConfig(FlowConfigModel model);

		public ResultData<string> DeleteFlowConfigs(List<string> ids);

        public PageData<Nasty.Core.Entity.Flow.FlowConfig> GetFlowConfigPage(GetFlowConfigPageParams @params);

		public ResultData<string> SwitchFlowConfigPublish(SwitchFlowConfigPublishParams @params);

		public ResultData<string> SaveFlowConfigNodes(BatchParams<FlowConfigNodeModel> models);

        public List<Nasty.Core.Entity.Flow.FlowConfigNode> GetFlowConfigNodes(string configId);
    }

	public class FlowConfigService : IFlowConfigService
	{
		public required IFlowConfigRepository FlowConfigRepository { get; set; }

		public ResultData<string> DeleteFlowConfigs(List<string> ids)
		{
			return FlowConfigRepository.DeleteFlowConfigs(ids);
		}

        public PageData<Nasty.Core.Entity.Flow.FlowConfig> GetFlowConfigPage(GetFlowConfigPageParams @params)
        {
            return FlowConfigRepository.GetFlowConfigPage(@params);
        }

        public Nasty.Core.Entity.Flow.FlowConfig GetFlowConfig(string id)
		{
			return FlowConfigRepository.GetFlowConfig(id);
		}

		
		public ResultData<Nasty.Core.Entity.Flow.FlowConfig> SaveFlowConfig(FlowConfigModel model)
		{
			return FlowConfigRepository.SaveFlowConfig(model);
		}

        public List<Nasty.Core.Entity.Flow.FlowConfig> GetFlowConfigs(GetFlowConfigsParams @params)
        {
            return FlowConfigRepository.GetFlowConfigs(@params);
        }

        public ResultData<string> SwitchFlowConfigPublish(SwitchFlowConfigPublishParams @params)
        {
            return FlowConfigRepository.SwitchFlowConfigPublish(@params);
        }

        public ResultData<string> SaveFlowConfigNodes(BatchParams<FlowConfigNodeModel> models)
        {
            return FlowConfigRepository.SaveFlowConfigNodes(models);
        }

        public List<Nasty.Core.Entity.Flow.FlowConfigNode> GetFlowConfigNodes(string configId)
        {
            return FlowConfigRepository.GetFlowConfigNodes(configId);
        }
    }
}
